package load;

import javacard.framework.*;
import javacard.framework.*;

public class LoadApp extends Applet {

	private byte[] pA = new byte[]{0x11, 0x22, 0x33, 0x44};
	private byte[] pB = new byte[]{0x55, 0x66, 0x77, (byte)0x88};
	
	public static void install(byte[] bArray, short bOffset, byte bLength) {
		LoadApp pApp = new LoadApp();
		pApp.register(bArray, (short) (bOffset + 1), bArray[bOffset]);
	}
	
	void f()
	{
		byte b;
		JCSystem.beginTransaction();
		Util.arrayCopy(pA, (short)0, pB, (short)0, (short)0x04);
		b = pB[1];
		Util.arrayCopyNonAtomic(pA, (short)0, pB, (short)0, (short)0x04);
		b = pB[1];
		Util.arrayFillNonAtomic(pB, (short)0, (short)0x04, (byte)0xFF);
		b = pB[1];
		
		Util.arrayCopyNonAtomic(pA, (short)0, pB, (short)0, (short)0x04);
		b = pB[1];
		Util.arrayCopy(pA, (short)0, pB, (short)0, (short)0x04);
		b = pB[1];
		
	}

	public void process(APDU apdu) {
		if (selectingApplet()) {
			return;
		}

		byte[] buf = apdu.getBuffer();
		switch (buf[ISO7816.OFFSET_INS]) {
		case (byte)0x00:
			f();
			break;
		default:
			ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
		}
	}

}
